package com.changhong.disruptorsource.websocket;

import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOServer;
import io.netty.util.internal.PlatformDependent;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by Administrator on 2018/10/25
 */
public class SocketServer {
    public static void main(String[] args) throws InterruptedException {
        Configuration config = new Configuration();
        config.setHostname("localhost");
        config.setPort(9092);

        SocketIOServer server = new SocketIOServer(config);

        CharteventListener listner = new CharteventListener();
        listner.setServer(server);
        //   chatevent为事件名称
        server.addEventListener("chatevent", ChatObject.class, listner);
        //启动服务
        server.start();

        new Thread(() -> {
            while (true) {
                int kb = 1024;
                int mb = 1024 * 1024;
                try {
                    Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_COUNTER");
                    field.setAccessible(true);
                    AtomicLong directMemory = (AtomicLong) field.get(PlatformDependent.class);
                    System.err.println("directMemory: " + directMemory.get());
                    Thread.sleep(1000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();

        Thread.sleep(Integer.MAX_VALUE);

        server.stop();
    }
}
